class Tea {
    constructor(id, teaName, teaType, teaPrice, teaImg) {
        this.id = id;
        this.teaName = teaName;
        this.teaType = teaType;
        this.teaPrice = teaPrice;
        this.teaImg = teaImg;
    }
}

// 添加茶叶
Mock.mock("/js/addTea","post",function(obj){
    let bodyObj = JSON.parse(obj.body)
    // 获取本地存储
    let teaString = localStorage.Tea;
    // 判断本地存储是否存在
    if(teaString == "" || teaString == null || teaString == undefined || teaString == []){
        let tea = new Tea(bodyObj.id,bodyObj.teaName,bodyObj.teaType,bodyObj.teaPrice,bodyObj.teaImg);
        let arr = [tea]
        localStorage.Tea = JSON.stringify(arr)
        return true
    }else{
        // 设置标记值
        let bool = false;
        // 本地存储 字符串转对象数组
        let teaobj = JSON.parse(teaString)
        for(let i=0; i<teaobj.length;i++){
            if(teaobj[i].teaName==bodyObj.teaName){
                bool = true;
                break;
            }
        }
        if(bool){
            return false;
        }else{
            let tea = new Tea(bodyObj.id,bodyObj.teaName,bodyObj.teaType,bodyObj.teaPrice,bodyObj.teaImg);
            teaobj.push(tea);
            localStorage.Tea=JSON.stringify(teaobj);
            return true;
        }
    }
})